# -*- coding: utf-8 -*-
import scrapy
from spCrawl.items import Tencent
from scrapy.log import logger

class TencentSpider(scrapy.Spider):
    name = 'tencent'
    allowed_domains = ['hr.tencent.com']
    url = "https://hr.tencent.com/position.php?&start="
    offset = 0
    start_urls = [
        url + str(offset)
    ]


    def parse(self, response):
        for each in response.xpath("//tr[@class='even'] | //tr[@class='odd']"):
            tencent = Tencent()
            tencent["name"] = each.xpath("./td[1]/a/text()").extract()[0]
            tencent["type"] = each.xpath("./td[2]/text()").extract()[0]
            tencent["count"] = each.xpath("./td[3]/text()").extract()[0]
            tencent["position"] = each.xpath("./td[4]/text()").extract()[0]
            tencent["time"] = each.xpath("./td[5]/text()").extract()[0]
            yield tencent

        # 3360
        while self.offset < 3360:
            self.offset = self.offset + 10
            yield scrapy.Request(url=self.url + str(self.offset), callback=self.parse)
